﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Actuals.CoreDomain;
using Actuals.CoreDomain.Business;
using Actuals.CoreDomain.Data;
using Actuals.Data;

namespace Actuals.Business
{
    public class BusinessPartTimeDetail : IBusinessPartTimeDetail
    {

         private IDalPartTimeDetails _dalPartTimeDetails;
        private IBusinessRelease _businessRelease;

         public BusinessPartTimeDetail(IDalPartTimeDetails dalPartTimeDetails)
        {
            _dalPartTimeDetails = dalPartTimeDetails;
        }

         public BusinessPartTimeDetail()
        {
            _dalPartTimeDetails = new DalPartTimeDetails();
        }

         public BusinessPartTimeDetail(IDalPartTimeDetails dalPartTimeDetails, IBusinessRelease businessRelease )
         {
             _dalPartTimeDetails = dalPartTimeDetails;
             _businessRelease = businessRelease;
         }


        public IList<IPartTimeDetails> GetPartTimeDetails(int employeeId)
        {
            return _dalPartTimeDetails.GetPartTimeDetails(employeeId);
        }

        public IList<IPartTimeDetails> GetPartTimeDetails(int projectId, int releaseId, int employeeId)
        {
            IBusinessRelease businessRelease = new BusinessRelease();
            IRelease release = businessRelease.GetRelease(projectId, releaseId);

            IList<IPartTimeDetails> partTimeDetailses = GetPartTimeDetails(employeeId);

            IList<IPartTimeDetails> _partTimeDetails = partTimeDetailses.ToList().FindAll
                (delegate(IPartTimeDetails partTimeDetails) { return (partTimeDetails.WorkDate >= release.StartDate 
                                                                && partTimeDetails.WorkDate <= release.EndDate) ; });


            return _partTimeDetails;
        }

        public IList<IPartTimeDetails> GetPartTimeDetails(DateTime startDate, DateTime endDate, int employeeId)
        {
           

            IList<IPartTimeDetails> partTimeDetailses = GetPartTimeDetails(employeeId);

            IList<IPartTimeDetails> _partTimeDetails = partTimeDetailses.ToList().FindAll
                (delegate(IPartTimeDetails partTimeDetails)
            {
                return (partTimeDetails.WorkDate >= startDate
                  && partTimeDetails.WorkDate <= endDate);
            });


            return _partTimeDetails;
        }

        public IList<IPartTimeDetails> GetPartTimeDetailsForTeam(int teamId)
        {
            return _dalPartTimeDetails.GetPartTimeDetailsForTeam(teamId);
        }
        public bool AddPartTimeDetails(IPartTimeDetails partTimeDetails)
        {
           return  _dalPartTimeDetails.AddPartTimeDetails(partTimeDetails);
        }
        public bool DeletePartTimeDetails(int partTimeId)
        {
           return  _dalPartTimeDetails.DeletePartTimeDetails(partTimeId);
        }
        public bool IsInValidDate(DateTime date, int employeeId)
        {

            return (
                    (date.DayOfWeek == DayOfWeek.Saturday)
                     || (date.DayOfWeek == DayOfWeek.Sunday)
                     || ((new BusinessPublicHoliday()).IsPublicHoliday(date))
                     || ((new BusinessEmployeeLeave()).IsEmployeeOnLeave(employeeId, date))
                     );





        }

    }
}
